package com.itmg.admin.business.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.itmg.admin.business.service.AdminService;
import com.itmg.dao.TopImageDAO;
import com.itmg.dao.model.KeywordsModel;
import com.itmg.dao.model.TopImageModel;
import com.itmg.factory.DAOFactory;
import com.itmg.util.KeywordsContainer;

public class AdminServiceImpl implements AdminService {
	
	private TopImageDAO topImageDAO = DAOFactory.getTopImageDAO();
//	private KeywordsDAO keywordsDAO = DAOFactory.getKeywordsDAO();

	@Override
	public List<TopImageModel> getTopImage() throws Exception {
		List<TopImageModel> list = topImageDAO.getTopImage();
//		Collections.shuffle(list);
		if(list.size()>8)
			return list.subList(0, 8);
		else
			return list;
	}

	@Override
	public void save(TopImageModel model) throws Exception {
		topImageDAO.save(model);
	}

	@Override
	public List<KeywordsModel> getTopKeyword() throws Exception {
		List<KeywordsModel> list = KeywordsContainer.getKeywordsList();
		Collections.shuffle(list);
		//去掉太长的关键字 add by kindy
		List<KeywordsModel> list_temp = new ArrayList<KeywordsModel>();
		for(KeywordsModel keywordsModel : list){
			if(keywordsModel.getKeywords() != null 
					&& !"".equals(keywordsModel.getKeywords()) 
					&& keywordsModel.getKeywords().length() <= 10){
				list_temp.add(keywordsModel);
			}
		}
		if(list_temp.size()>24)
			return list_temp.subList(0, 24);
		else
			return list_temp;
	}

}
